//
//  HomeItemCell.m
//  Kjs
//
//  Created by cfq on 16/4/17.
//  Copyright © 2016年 kjs. All rights reserved.
//

#import "HomeItemCell.h"
#import "CommonUtil.h"
@interface HomeItemCell ()

@property (nonatomic,weak) IBOutlet UILabel *itemNameLab;
@property (nonatomic,weak) IBOutlet UILabel *gdAnnualizedBenefitRateLab;
@property (nonatomic,weak) IBOutlet UILabel *interestDaysLab;
@property (nonatomic,weak) IBOutlet UILabel *targetMoneyLab;
@property (nonatomic,weak) IBOutlet UILabel *raiseRateLab;
@property (nonatomic,weak) IBOutlet UIProgressView *raiseRatePV;
@property (nonatomic,weak) IBOutlet UIImageView *itemStatusImageV;
@property (nonatomic,weak) IBOutlet UILabel *remindMoneyLab;


@end

@implementation HomeItemCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setItem:(ItemInfo *)item
{
    //金额格式化
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    NSString *targetMoneyStr = [formatter stringFromNumber:[NSNumber numberWithDouble:item.targetMoney]];
    NSString *remindMoneyStr = [formatter stringFromNumber:[NSNumber numberWithDouble:(item.targetMoney - item.raiseMoney)]];
    self.itemNameLab.text = item.itemName;
    
    //去掉小数点后多余的0
    NSString *gdAnnualizedBenefitRate = [NSString stringWithFormat:@"%.2lf％",item.gdAnnualizedBenefitRate*100];
    NSString * outNumber = [CommonUtil subZeorFrom:gdAnnualizedBenefitRate];
    self.gdAnnualizedBenefitRateLab.text = [NSString stringWithFormat:@"%@％",outNumber];
    
    self.interestDaysLab.text = [NSString stringWithFormat:@"%d天",item.interestDays];
    self.targetMoneyLab.text = [NSString stringWithFormat:@"¥%@元",targetMoneyStr];
    self.raiseRateLab.text = [NSString stringWithFormat:@"%.2lf％",(item.raiseMoney*100)/item.targetMoney];
    self.raiseRatePV.progress = item.raiseMoney/item.targetMoney;
    switch (item.itemStatus) {
        case 7:
            self.itemStatusImageV.image = [UIImage imageNamed:@"item-qianggou"];
            break;
        case 8:
            self.itemStatusImageV.image = [UIImage imageNamed:@"item-preparing"];
            break;
        case 9:
            if ([item.gdBenefitReturnStep containsString:@"还款中"]) {
                self.itemStatusImageV.image = [UIImage imageNamed:@"return-benefit-ing"];
            }else if ([item.gdBenefitReturnStep containsString:@"还款完成"]){
                self.itemStatusImageV.image = [UIImage imageNamed:@"return-benefit-finish"];
            }else{
                self.itemStatusImageV.image = [UIImage imageNamed:@"item-selout"];
            }
            break;
        default:
            self.itemStatusImageV.image = [UIImage imageNamed:@""];
            break;
    }
    self.remindMoneyLab.text = [NSString stringWithFormat:@"¥%@",remindMoneyStr];
    
}
@end
